package com.rickpan.service;

import com.rickpan.entity.Project;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

/**
 * 项目服务接口
 * 
 * @author RickPan Team
 * @since 2024-01-15
 */
public interface ProjectService {

    /**
     * 创建项目
     */
    Project createProject(Project project);

    /**
     * 更新项目
     */
    Project updateProject(Project project);

    /**
     * 删除项目
     */
    void deleteProject(Long projectId);

    /**
     * 根据ID查找项目
     */
    Optional<Project> findById(Long projectId);

    /**
     * 根据团队ID查找项目列表
     */
    List<Project> findProjectsByTeam(Long teamId);

    /**
     * 根据团队ID查找项目列表（分页）
     */
    Page<Project> findProjectsByTeam(Long teamId, Pageable pageable);

    /**
     * 根据团队ID和状态查找项目列表
     */
    List<Project> findProjectsByTeamAndStatus(Long teamId, Project.Status status);

    /**
     * 根据团队ID和状态查找项目列表（分页）
     */
    Page<Project> findProjectsByTeamAndStatus(Long teamId, Project.Status status, Pageable pageable);

    /**
     * 根据项目经理ID查找项目列表
     */
    List<Project> findProjectsByManager(Long projectManagerId);

    /**
     * 根据项目经理ID和状态查找项目列表
     */
    List<Project> findProjectsByManagerAndStatus(Long projectManagerId, Project.Status status);

    /**
     * 搜索项目
     */
    List<Project> searchProjects(Long teamId, String keyword);

    /**
     * 搜索项目（分页）
     */
    Page<Project> searchProjects(Long teamId, String keyword, Pageable pageable);

    /**
     * 查找活跃项目
     */
    List<Project> findActiveProjects(int limit);

    /**
     * 查找即将到期的项目
     */
    List<Project> findProjectsDueSoon(int days);

    /**
     * 查找逾期项目
     */
    List<Project> findOverdueProjects();

    /**
     * 根据团队ID查找逾期项目
     */
    List<Project> findOverdueProjectsByTeam(Long teamId);

    /**
     * 更新项目进度
     */
    void updateProjectProgress(Long projectId);

    /**
     * 更新项目进度（手动设置）
     */
    void updateProjectProgress(Long projectId, Integer progress);

    /**
     * 更新项目状态
     */
    void updateProjectStatus(Long projectId, Project.Status status);

    /**
     * 分配项目经理
     */
    void assignProjectManager(Long projectId, Long projectManagerId);

    /**
     * 获取项目统计信息
     */
    ProjectStatistics getProjectStatistics(Long teamId);

    /**
     * 检查用户是否有项目管理权限
     */
    boolean hasProjectManagePermission(Long projectId, Long userId);

    /**
     * 检查用户是否有项目查看权限
     */
    boolean hasProjectViewPermission(Long projectId, Long userId);

    /**
     * 项目统计信息类
     */
    class ProjectStatistics {
        private long totalProjects;
        private long activeProjects;
        private long completedProjects;
        private long overdueProjects;
        private double averageProgress;

        // 构造函数
        public ProjectStatistics() {}

        public ProjectStatistics(long totalProjects, long activeProjects, long completedProjects, 
                               long overdueProjects, double averageProgress) {
            this.totalProjects = totalProjects;
            this.activeProjects = activeProjects;
            this.completedProjects = completedProjects;
            this.overdueProjects = overdueProjects;
            this.averageProgress = averageProgress;
        }

        // Getter 和 Setter
        public long getTotalProjects() { return totalProjects; }
        public void setTotalProjects(long totalProjects) { this.totalProjects = totalProjects; }

        public long getActiveProjects() { return activeProjects; }
        public void setActiveProjects(long activeProjects) { this.activeProjects = activeProjects; }

        public long getCompletedProjects() { return completedProjects; }
        public void setCompletedProjects(long completedProjects) { this.completedProjects = completedProjects; }

        public long getOverdueProjects() { return overdueProjects; }
        public void setOverdueProjects(long overdueProjects) { this.overdueProjects = overdueProjects; }

        public double getAverageProgress() { return averageProgress; }
        public void setAverageProgress(double averageProgress) { this.averageProgress = averageProgress; }
    }
}
